<?php
namespace app\index\controller;

use app\common\controller\CustomOutput;
use think\Controller;

class Index extends Controller
{
    protected $coutHandler;
    
    public function __construct() {
        parent::__construct();
        $this->coutHandler = new CustomOutput();
    }
    
    public function index()
    {
        return '<br>index访问错误';
        exit;
    }
    
    // 对外接口-返回当前/偏移时间数组
    // offset参考
    // +3s +3min +3hour +3day +3month +3year
    // (已弃用)
    public function getCurTimeAction() {
        
        $offset = $this->request->param('offset', 'now');
        
        $data = array(
            'cur' => array(),
            'curOffset' => array()
        );
        
        $data['cur']['year']   = date('Y');
        $data['cur']['month']  = date('m');
        $data['cur']['day']    = date('d');
        $data['cur']['hour']   = date('H');
        $data['cur']['min']    = date('i');
        $data['cur']['all']    = date('Y-m-d H:i');
        
        $data['curOffset']['year']   = date('Y', strtotime($offset));
        $data['curOffset']['month']  = date('m', strtotime($offset));
        $data['curOffset']['day']    = date('d', strtotime($offset));
        $data['curOffset']['hour']   = date('H', strtotime($offset));
        $data['curOffset']['min']    = date('i', strtotime($offset));
        $data['curOffset']['all']    = date('Y-m-d H:i', strtotime($offset));
        
        $this->coutHandler->outputJson(lang('custom success'), 200, $data);
    }
}
